﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Actor : MonoBehaviour
{
    public SpriteRenderer spriteRenderer;
    protected Animator animator;
    [HideInInspector]
    public Vector2 speedVal = Vector2.zero;
    public bool revertForward = false;
    [HideInInspector]
    public float forward { get { return revertForward ? -(spriteRenderer.flipX ? -1 : 1) : (spriteRenderer.flipX ? -1 : 1); } }
    public bool isDeath = false;
    protected bool isHit = false;
    public Action onDeath;
    [HideInInspector]
    public ActorInfo actorInfo;
    public Rigidbody2D rig;
    protected virtual void Awake()
    {
        rig = GetComponent<Rigidbody2D>();
        animator = GetComponent<Animator>();
        spriteRenderer = GetComponent<SpriteRenderer>();
    }
    public void BindActorInfo(ActorInfo acterInfo)
    {
        this.actorInfo = acterInfo;
    }
    /// <summary>
    /// 击退
    /// </summary>
    /// <returns></returns>
    public IEnumerator ToRepel(Vector3 dir, float time)
    {
        float t = 0;
        isHit = true;
        while (t < time)
        {
            t += Time.deltaTime;
            transform.position += dir * Time.deltaTime * (1 - t / time);
            yield return null;
        }
        isHit = false;
        yield return null;
    }

}
